package com.sun.rabbitMQ.WorkQueues;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.sun.rabbitMQ.utils.FactoryUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConsumerACK1 {
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = FactoryUtils.getChannel();
        System.out.println("ACK1消费消息");
        DeliverCallback deliverCallback = (var1, var2)->{
            String message = new String(var2.getBody());
            System.out.println(message);
            try {
                Thread.sleep(30000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            channel.basicAck(var2.getEnvelope().getDeliveryTag(),false);

        };
        //不公平分发
        int prefetchCount = 1;
        channel.basicQos(prefetchCount);
        channel.basicConsume(FactoryUtils.TASK_QUEUE_NAME,false,deliverCallback,(var->{
            System.out.println("消费者取消消费回调");
        }));
    }
}
